using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using System.Web.Security;
using DomesticBank.Models;


namespace DomesticBank.Controllers {
	[HandleError]
	public class TransactionsController : Controller {
		[Authorize]
		public ActionResult Index() {
			return View();
		}
		
		
		[Authorize]
		public ActionResult Add(int id) {
			ViewData["accountid"] = id;
			return View();
		}
		
		
		[Authorize]
		public ActionResult NewTransaction(int id, string name, string beneficiary, decimal income, decimal expenses, string description, string tags, DateTime date, TimeSpan time, int payment = 0, int category = 0) {
			AccountsData data = new AccountsData();
			Transaction transaction = new Transaction();
			
			transaction.Name = name;
			transaction.Beneficiary = beneficiary;
			transaction.Income = income;
			transaction.Expenses = expenses;
			transaction.Description = description;
			transaction.Payment = (payment != null) ? payment : 0;
			transaction.Category = (category != null) ? category : 0;
			transaction.Date = date;
			transaction.Time = time;
			
			data.addTransaction(id, transaction);
			
			return RedirectToAction("Account", "Accounts", new { id = id });
		}
	}
}